import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import com.kizitonwose.calendar.compose.HorizontalCalendar
import com.kizitonwose.calendar.compose.WeekCalendar
import com.kizitonwose.calendar.compose.rememberCalendarState
import com.kizitonwose.calendar.compose.weekcalendar.rememberWeekCalendarState
import com.kizitonwose.calendar.core.CalendarDay
import com.kizitonwose.calendar.core.WeekDay
import com.kizitonwose.calendar.core.atStartOfMonth
import com.kizitonwose.calendar.core.firstDayOfWeekFromLocale
import java.time.LocalDate
import java.time.YearMonth

/*
*author:guyueyuan
*createTime:2024/11/17
*/

@SuppressLint("RememberReturnType")
@Composable
fun MyCalendar() {
//    当前月
    val currentMonth = remember { YearMonth.now() }
//    开始月
    val startMonth = remember { currentMonth.minusMonths(100) } // Adjust as needed
//    结束月
    val endMonth = remember { currentMonth.plusMonths(100) } // Adjust as needed
    val firstDayOfWeek = remember { firstDayOfWeekFromLocale() } // Available from the library

    val state = rememberCalendarState(
        startMonth = startMonth,
        endMonth = endMonth,
//        当前展示月
        firstVisibleMonth = currentMonth,
        firstDayOfWeek = firstDayOfWeek
    )

    HorizontalCalendar(
        modifier = Modifier.background(color = Color.Yellow),
        state = state,
        dayContent = { Day1(it) }
    )

//    If you need a vertical calendar.
//    VerticalCalendar(
//        state = state,
//        dayContent = { Day(it) }
//    )

//    val state = rememberWeekCalendarState(
////    开始时间
//        startDate = YearMonth.now().atStartOfMonth(),
////    结束时间
//        endDate = YearMonth.now().atEndOfMonth(),
////    默认展示周
//        firstVisibleWeekDate = LocalDate.now(),
////    一周的第一天
//        firstDayOfWeek = firstDayOfWeek
//    )
//
//    WeekCalendar(
//        state = state,
//        dayContent = { Day2(it) }
//    )
}

@Composable
fun Day1(it: CalendarDay) {
    Text(it.date.dayOfMonth.toString(), color = Color.Red)
}

@Composable
fun Day2(it: WeekDay) {
    Text(it.date.dayOfMonth.toString(), color = Color.Red)
}

@Preview
@Composable
fun MyCalendarPre() {
    MyCalendar()
}